package com.example.memory.base.controller;

import com.example.memory.base.service.BaseService;
import com.example.memory.base.entity.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

public class BaseController<T> {
    @Autowired
    protected BaseService<T> baseService;

    @DeleteMapping("/delete")
    public ResultMsg delete(String key) {
        baseService.delete(key);
        return ResultMsg.success();
    }

    @PostMapping("/update")
    public ResultMsg update(@RequestBody T t) {
        baseService.update(t);
        return ResultMsg.success();
    }

    @GetMapping("/getOne")
    public ResultMsg select(String key) {
        return ResultMsg.success(baseService.select(key));
    }

    @PostMapping("/insert")
    public ResultMsg insert(@RequestBody T t) {
        baseService.insert(t);
        return ResultMsg.success();
    }

    @GetMapping("/getList")
    public List<T> getList(T t) {
        return baseService.getList(t);
    }
}
